import { ARRIVAL_WARNING_STATUS_OPTIONS, ORDER_STATUS_TRACKING_OPTIONS, PURCHASEWAY_OPTIONS } from '@/constant/purchase'
import { getRecentSixMonths } from '@/utils/util'
import { Empty, FormInstance } from 'antd'
import dayjs from 'dayjs'
const defaultDateRange = getRecentSixMonths()

export const searchConfig = ({
  SpuOptions,
  handleSearchSpuOptions,
  SupplierOption,
  handleSearchSupplier,
  classBig,
  UserOptions,
  handleSearchUser,
  ColorOptions,
  handleSearchColor,
  form,
}: {
  SpuOptions: IOptionItem[]
  handleSearchSpuOptions: (newValue?: string) => void
  classBig: IOptionItem[]
  SupplierOption: IOptionItem[]
  handleSearchSupplier: (newValue?: string) => void
  UserOptions: IOptionItem[]
  handleSearchUser: (newValue?: string) => void
  ColorOptions: IOptionItem[]
  handleSearchColor: (newValue?: string) => void
  form: FormInstance
}): IItemArray[] => {
  return [
    {
      label: '采购订单',
      name: 'purchaseOrderCodes',
      placeholder: '多个单号间需要换行或使用","分隔',
      type: 'Select',
      config: {
        mode: 'tags',
        maxTagCount: 'responsive',
        tokenSeparators: [',', '，', '\n', '\r', '\r\n'],
        notFoundContent: null,
      },
    },
    {
      label: '正式订单时间',
      name: 'officialOrderTimeStart',
      type: 'FixedRangePicker',
      rules: [{ required: true, message: '请选择正式订单时间' }],
      config: {
        showTime: false,
        customFormat: 'YYYY-MM-DD',
        presets: [
          {
            label: '最近一年',
            value: [dayjs().subtract(6, 'month'), dayjs().add(6, 'month')],
          },
          {
            label: '最近六个月',
            value: defaultDateRange,
          },
        ],
        disabledDate: (current: any, { from }: any) => {
          if (from) {
            return current.isAfter(from.add(1, 'year')) || current.isBefore(from.subtract(1, 'year'))
          }
          return false
        },
      },
    },
    {
      label: '采购订单状态',
      name: 'statuses',
      type: 'Select',
      option: ORDER_STATUS_TRACKING_OPTIONS,
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: true,
        onChange: (val: string) => {
          form.setFieldValue('selectKey', [])
        },
      },
    },
    {
      name: 'supplierIdList',
      label: '供应商',
      type: 'Select',
      option: SupplierOption,
      placeholder: '请选择供应商',
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        mode: 'multiple',
        maxTagCount: 'responsive',
        onSearch: handleSearchSupplier,
      },
    },
    {
      label: '大类',
      name: 'firstClassConfigIdList',
      type: 'Select',
      option: classBig,
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        mode: 'multiple',
        maxTagCount: 'responsive',
      },
    },
    {
      label: '供应链跟单',
      name: 'trackOrderPersonWorkId',
      type: 'Select',
      option: UserOptions,
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        onSearch: handleSearchUser,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
        fieldNames: { label: 'label', value: 'workId' },
      },
    },
    {
      label: '要求到货日期',
      name: 'requiredArrivalTimeStart',
      type: 'FixedRangePicker',
      config: { showTime: false, customFormat: 'YYYY-MM-DD' },
    },
    {
      label: '采购方式',
      name: 'queryPurchaseTypeList',
      type: 'Select',
      option: PURCHASEWAY_OPTIONS,
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        mode: 'multiple',
        maxTagCount: 'responsive',
      },
    },
    {
      label: '订单类型',
      name: 'orderType',
      type: 'Select',
      option: [
        { label: '首单', value: 0 },
        { label: '返单', value: 1 },
      ],
      config: {
        showSearch: true,
        optionFilterProp: 'label',
      },
    },
    {
      label: 'SPU商品',
      name: 'spuCode',
      type: 'Select',
      option: SpuOptions,
      placeholder: '款式编码/款式名称/助记码/工厂款号',
      config: {
        showSearch: true,
        filterOption: false,
        optionFilterProp: 'label',
        onSearch: handleSearchSpuOptions,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
      },
    },
    {
      name: 'colorDetailNames',
      label: '款式色',
      type: 'Select',
      option: ColorOptions,
      placeholder: '请选择款式色',
      config: {
        showSearch: true,
        filterOption: false,
        optionFilterProp: 'label',
        mode: 'multiple',
        maxTagCount: 'responsive',
        onSearch: handleSearchColor,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
      },
    },
    {
      name: 'arrivalWarningStatues',
      label: '到货预警情况',
      type: 'Select',
      option: ARRIVAL_WARNING_STATUS_OPTIONS,
      placeholder: '请选择到货预警情况',
      config: {
        showSearch: true,
        optionFilterProp: 'label',
        mode: 'multiple',
        maxTagCount: 'responsive',
      },
    },
  ]
}

export const useFormExport = (): IItemArray[] => {
  return [
    {
      label: '导出数据维度',
      name: 'exportDataTypeList',
      type: 'Checkbox',
      option: [
        { label: '色', value: 'exportSkc' },
        { label: '尺码', value: 'exportSku' },
      ],
    },
  ]
}
